<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
    <title>csgmap-psr-filter</title>
    <style>
        html,
        body,
        #mapui {
            width: 100%;
            height: 100%;
        }
        
        html,
        body {
            margin: 0;
            padding: 0;
        }
    </style>
</head>

<body>
    <div id="mapui"></div>
    <button type="button" onclick="testFun()" style="position: absolute;top: 10px;right: 10px;">清除</button>
    <button type="button" onclick="btnA()" style="position: absolute;top: 40px;right: 10px;">A</button>
    <button type="button" onclick="btnB()" style="position: absolute;top: 80px;right: 10px;">B</button>
    <button type="button" onclick="btnC()" style="position: absolute;top: 120px;right: 10px;">C</button>
    <script src="./js_example/script/map.min.js"></script>
    <script src="./js_example/script/psr.min.js"></script>
    <script src="./js_example/script/demo.js"></script>
    <script>
        var amap = null;
        var psrmap = null;
        var filter = null;
        var init = false;
        // psr.Identify.loginByUserName('bs01', '1');
        // psr.Globals.Config.Host = 'http://172.16.12.38:6081';
        map.Factory.create('mapui', {
            style: style,
            center: center,
            zoom: 5,
            strategy: ['mapboxgl', 'openlayers', 'leaflet'],
        }, (o) => {
            amap = o;
            psrmap = new psr.PSRMap(o.pmap);
            //psrmap.addPSR([], ['Open Sans Regular', 'Arial Unicode MS Regular']);
            psrmap.addPSR([], ['Microsoft YaHei UI Regular']);
            filter = new psr.Display.Filter(o.pmap);
            init = true;
        });

        var flag = 1;

        function btnA() {
            if (!init) {
                console.log('please waite init');
                return;
            }

            // filter.filterByVoltage([10000], flag % 2 == 0);
            // filter.filterByClassID([110], flag % 2 == 0);      
            // filter.filterByUseType([psr.Globals.PSRUseType.distribution, psr.Globals.PSRUseType.lowVoltage], flag % 2 == 0);
            // flag++;
            this.psrmap.setVisiable(flag % 2 == 0);
            flag++;
        }

        var flagA = 1;

        function btnB() {
            if (!init) {
                console.log('please waite init');
                return;
            }

            // filter.filterByVoltage([10000], flag % 2 == 0);
            // filter.filterByClassID([110], flag % 2 == 0);      
            filter.filterByUseType([psr.Globals.PSRUseType.lowVoltage], true);
            // flagA++;
        }


        var flagC = 1;

        function btnC() {
            if (!init) {
                console.log('please waite init');
                return;
            }

            // filter.filterByVoltage([10000], flag % 2 == 0);
            // filter.filterByClassID([110], flag % 2 == 0);      
            filter.filterByUseType([psr.Globals.PSRUseType.lowVoltage, psr.Globals.PSRUseType.transformation,
                psr.Globals.PSRUseType.generation, psr.Globals.PSRUseType.transmission, psr.Globals.PSRUseType.distribution
            ], false);
            flagC++;
        }

        function testFun() {
            filter.clearFilters();
        }
    </script>
</body>

</html>